package com.fognl.core.net.handler.request;

import com.fognl.core.net.handler.AbstractRequest;
import com.fognl.core.net.handler.Request;
import com.fognl.core.net.handler.WorkerException;

public class TakeForeverRequest extends AbstractRequest
{
	private String message;
	
	public TakeForeverRequest(String msg)
	{
		super();
		this.message = msg;
	}
	
	public String toString()
	{
		return "{TakeForeverRequest: " + message + "}";
	}
	
	public Worker getWorker()
	{
		return new Worker() {

			public Object getData()
			{
				return TakeForeverRequest.this.message;
			}
			
			public void work(Request.Worker.Listener listener) throws WorkerException
			{
				for(;;)
				{
					try {
						Thread.sleep(1000L);
						if(!listener.okToContinue(this))
							break;
						
						listener.onData(message);
					}
					catch(Exception ex)
					{
						throw new WorkerException(ex);
					}
				}
			}
		};
	}
}
